home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6916 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  72 lines

  1. Path: inferno.mpx.com.au!news
  2. From: Malcolm Smith <mjsmith@mpx.com.au>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fopen not working
  5. Date: 16 Feb 1996 07:19:57 GMT
  6. Organization: Microplex Pty Ltd
  7. Message-ID: <4g1b6t$2ra@inferno.mpx.com.au>
  8. References: <4fjnj1$4q@fig.leba.net>
  9. NNTP-Posting-Host: dialup-211.mpx.com.au
  10.  
  11. fweaver@leba.net wrote:
  12. >
  13. > Good evening to all C programers
  14. >    I have a problem I thought someone might be able to shed some light on 
  15. > for me. Below is some of the code I wrote for an install program.
  16. > #include<stdio.h>
  17. > #include<conio.h>
  18. > char buf[125],stwd[110],trwd[110],*pt,*pt1;
  19. > int i,vr,vd;
  20. > FILE *in, *out;
  21. > main()
  22. > {   [snip]
  23. >  
  24. >  instlfile("trkr.cf_","trkr.cfg");
  25. >  instlfile("maplvl3.da_","maplvl3.dat");
  26. >  instlfile("atpctrkr.do_","atpctrkr.doc");
  27. >  instlfile("readme.1s_","readme.1st");
  28. >  instlfile("file_id.di_","file_id.diz");
  29. >  
  30. >  [snip]
  31. >  if((in=fopen(buf,"r"))!=NULL)
  32. >   { do{ fgets(buf,120,in);
  33. >    pt= (char *)strstr(buf,"XXXXX");
  34. >    if(pt!=NULL){ fclose(out); pt=pt+5;if((out=fopen(pt,"w"))==NULL)printf("ERROR");
  35.  
  36. ---------
  37. Without testing the code my best guess is that on the first pass
  38. through the program detects the "XXXXX" and hence tries to close
  39. the previous file.  But there isn't one open yet.
  40. ---------
  41.  
  42. >  else{printf("\nInstalling %s",pt);continue; }}
  43. >    fputs(buf,out);
  44. >  }while(feof(in)==0);
  45. >  }
  46. > }
  47.  
  48. >  [snip]
  49. > instlfile(char f[15],char s[15])
  50. > { sprintf(buf,"%s%s",stwd,f);
  51. >  if((in=fopen(buf,"rb"))==NULL){close(in);return(0);}
  52.  
  53. ----------
  54. In the above line use fclose() for the corresponding fopen().
  55. ----------
  56.  
  57. >  if((out=fopen(s,"wb"))!=NULL)printf("\nInstalling %s",s);
  58. >  while((i=fgetc(in))!=EOF){fputc(i,out);}
  59. >  _fcloseall();
  60. > }
  61.  
  62.  
  63.  
  64. Regards,
  65.  
  66. Mal
  67.